import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:proj_sfv/domain/UserDetail.dart';
import 'package:proj_sfv/http/api.dart';
import 'package:http/http.dart' as http;
import 'package:proj_sfv/http/requests.dart';

class UserDetailScreen extends StatefulWidget {
  final int userId;
  final String token;
  final int myId;


  UserDetailScreen(this.userId, this.token, this.myId) {
    print('UserDetailScreen init: $userId, $token , $myId}');
  }

  @override
  State<UserDetailScreen> createState() => _UserDetailScreenState();
}

class _UserDetailScreenState extends State<UserDetailScreen> {
  UserDetail _detail = UserDetail.empty();

   @override
  void initState() {
     getUserDetailInfoRequest(context, widget.token, widget.userId).then((value) {
       setState(() {
         _detail = value;
       });
     });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(_detail.userName),
      ),
      body: Column(
        children: [
          SizedBox(
            height: 200,
            child: FutureBuilder(
              builder: (context, snapshot) => _detail.profile == null ? Image.asset("assets/owl.jpg") :
              Image.network(
                _detail.profile,
                fit: BoxFit.cover,
              ),
            )
          ),
        ],
      ),
      bottomNavigationBar: BottomAppBar(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            ElevatedButton.icon(
              onPressed: () {},
              icon: Icon(Icons.edit),
              label: Text('添加好友'),
            ),
            // ElevatedButton.icon(
            //   onPressed: () {},
            //   icon: Icon(Icons.delete),
            //   label: Text('删除好友'),
            // ),
            ElevatedButton.icon(
              onPressed: () {
                showDialog<String>(context: context, builder: (BuildContext context) => AlertDialog(
                  title: Text("提示"),
                  content: Text("取消关注"),
                  actions: [
                    TextButton(
                      onPressed: () => Navigator.pop(context, 'OK'),
                      child: const Text('确认'),
                    ),
                  ],
                ));
              },
              icon: Icon(Icons.unsubscribe_outlined),
              label: Text('取消关注'),
            ),
          ],
        ),
      ),
    );
  }
}
